/**
 * Copyright (c) 2018-2028, Joffee.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sailmi.system.feign;

import com.sailmi.common.model.auth.AuthUser;
import com.sailmi.common.tool.api.R;
import com.sailmi.system.entity.UcsAccountuser;
import com.sailmi.system.service.IUserService;
import com.sailmi.system.entity.UserInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户服务Feign实现类
 *
 * @author Joffee
 */
@RestController
public class UserClientFeignController implements IUserClient {
	@Resource
	private IUserService service;

	@Override
	public R<UserInfo> userInfo(Long userId) {
		return R.data(service.userInfo(userId));
	}


	@Override
	public R<UserInfo> userInfo(String tenantId,String account, String password) {
		return R.data(service.userInfo(tenantId,account, password));
	}

	@Override
	public R<AuthUser> registerUser(AuthUser authUser) {
		UcsAccountuser ucsAccountuser = new UcsAccountuser();
		ucsAccountuser.setId(authUser.getUserId());
		ucsAccountuser.setUsername(authUser.getAccount());
		ucsAccountuser.setUserEmail(authUser.getMail());
		ucsAccountuser.setPassword(authUser.getPassword());
		ucsAccountuser.setRealName(authUser.getUserName());
		ucsAccountuser.setCode(authUser.getUserCode());
		ucsAccountuser.setHeadImgUrl(authUser.getAvatar());
		ucsAccountuser.setUserPhone(authUser.getPhone());
		boolean rets = service.registerUser(ucsAccountuser);
		if(rets){
			return R.data(authUser);
		}else{
			return R.fail("注册失败");
		}
	}

	@Override
	public R<AuthUser> updateUser(AuthUser authUser) {
		return null;
	}

	@Override
	public R<List> getRoles(String userAccount) {
		return null;
	}

	@Override
	public R<List> getRights(String userAccount) {
		return null;
	}
}
